/**
 * Copyright European Commission's
 * Taxation and Customs Union Directorate-General (DG TAXUD).
 */
package com.eryos.bean;

import java.util.ArrayList;
import java.util.List;

public class Result {
    private List<String> listOfImages;
    private int position;
    private String id;
    private String title;
    private String price;
    private String location;
    private String date;
    private String link;
    private String content;

    public void addPicture(String img) {
        listOfImages.add(img);
    }

    public Result(int position) {
        this.position = position;
        listOfImages = new ArrayList<String>();
    }

    /**
     * @return the content
     */
    public String getContent() {
        return content;
    }

    /**
     * Sets the content.
     * 
     * @param content
     *            the value to set
     */
    public void setContent(String content) {
        this.content = content;
    }

    @Override
    public String toString() {
        String res = "";

        res += "#" + position + " - " + id + "\n";
        res += "Date : " + date + "\n";
        res += "Location : " + location + "\n";
        res += "Title : " + title + "\n";
        res += "Price : " + price + "\n";
        res += "Link : " + link + "\n";
        res += "Content : " + content + "\n";
        res += "Images : " + "\n";
        for (String img : listOfImages) {

            res += "      " + img + "\n";
        }

        return res;
    }

    public String toHTML() {
        String res = "";

        res = "<br><br>" + // <br>
                "<table border=1 width=\"100%\">" + // <br>
                "<tr style=\"background:#ffcc00;\">" + // <br>
                "   <td colspan=4><h3><a href=\"" + link + "\">[" + location + "] " + title + "</a></h3> <a href=\"mailto:?subject=Annonce Maison&body=Cette annonce est intéréssante : "+link+"\">Envoyer cette annonce par mail</a></td>" + // <br>
                "</tr>" + // <br>
                "<tr>" + // <br>
                "   <td><b>Id/Ref</b></td>" + // <br>
                "   <td><b>Date</b></td>" + // <br>
                "   <td><b>Lieu</b></td>" + // <br>
                "   <td><b>Prix</b></td>" + // <br>
                "</tr>" + // <br>
                "<tr>" + // <br>
                "   <td>" + position + " - " + id + "</td>" + // <br>
                "   <td>" + date + "</td>" + // <br>
                "   <td>" + location + "</td>" + // <br>
                "   <td>" + price + "</td>" + // <br>
                "</tr>" + // <br>
                "<tr>" + // <br>
                "   <td colspan=4>" + content + "</td>" + // <br>
                "</tr>";

        res += "<tr><td colspan=4>";
        for (String img : listOfImages) {

            if (showImage) {
                res += "<img src=\"" + img.replaceAll("\"", "'") + "\"></img> ";
            } else {
                res +=
                        "<span style=\"display: inline-block; width: 160px; height: 120px; "
                                + img.replaceAll("\"", "'") + "\"></span> ";
            }
        }
        res += "</td></tr>" + // <br>
                "</table>";
        return res;
    }

    boolean showImage = false;

    /**
     * @return the showImage
     */
    public boolean isShowImage() {
        return showImage;
    }

    /**
     * Sets the showImage.
     * 
     * @param showImage
     *            the value to set
     */
    public void setShowImage(boolean showImage) {
        this.showImage = showImage;
    }

    public Result() {
    }

    /**
     * @return the id
     */
    public String getId() {
        return id;
    }

    /**
     * Sets the id.
     * 
     * @param id
     *            the value to set
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * Sets the title.
     * 
     * @param title
     *            the value to set
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * @return the price
     */
    public String getPrice() {
        return price;
    }

    /**
     * Sets the price.
     * 
     * @param price
     *            the value to set
     */
    public void setPrice(String price) {
        this.price = price;
    }

    /**
     * @return the location
     */
    public String getLocation() {
        return location;
    }

    /**
     * Sets the location.
     * 
     * @param location
     *            the value to set
     */
    public void setLocation(String location) {
        this.location = location;
    }

    /**
     * @return the date
     */
    public String getDate() {
        return date;
    }

    /**
     * Sets the date.
     * 
     * @param date
     *            the value to set
     */
    public void setDate(String date) {
        this.date = date;
    }

    /**
     * @return the link
     */
    public String getLink() {
        return link;
    }

    /**
     * Sets the link.
     * 
     * @param link
     *            the value to set
     */
    public void setLink(String link) {
        this.link = link;
    }

}
